<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>新增方案</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <link rel="stylesheet" href="../../res/css/bootstrap.min.css">
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <style>
        .layui-form-label{
            width: 100px;
        }
    </style>

    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async: false
        });

    </script>

    <script type="text/javascript">
        $(function () {
            /*$.ajax({
                type:"GET",
                async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                url:"../../AtsSchemeController/FindModByManager",//获取option值得方法返回LIST<String>类型
                success:function(data){
                    $("#coachId").val(data.coachId);
                    $("#coachName").val(data.coachName);
                }

            });*/
            var mothed = getQueryString("mothed");
            var url = "../../User/findSession";
            $.post(url,null,function(obj){
                $("#coachId").val(obj.clerkId);
                $("#coachName").val(obj.userName);
            });

            var coachId = $("#coachId").val();//模拟从后台取到登陆人信息
            //超级管理员下显示所有运动员
            if(coachId == ""){
                $.ajax({
                    type:"GET",
                    async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                    url:"../../AtsSchemeController/selectAthletes",//获取option值得方法返回LIST<String>类型
                    success:function(data){
                        for(var i in data){        //遍历输出LIST添加为option
                            $("#athes").append("<input type='checkbox' name='athleteName' id='checkbox"+data[i].athleteId+"' value='"+data[i].athleteId+"' title='"+data[i].athleteName+"'>" );
                            // $("#athleteName").append("<option value='"+data[i].athleteName+"'>"+data[i].athleteName+"</option>");
                        }
                        if(mothed == 'update'){
                            var schemeId = getQueryString("schemeId");
                            $.ajax({
                                type:"GET",
                                async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                                url:"../../AtsSchemeController/selectAthleteName",//获取option值得方法返回LIST<String>类型
                                data:{'schemeId' : schemeId},
                                success:function(data){
                                    for(var i in data){        //遍历输出LIST添加为option
                                        $("#checkbox"+data[i].athleteId).prop('checked',true);
                                    }
                                }

                            });
                        }



                    }

                });

            }else{
                $.ajax({
                    type:"GET",
                    async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                    url:"../../AtsSchemeController/selectAthlete",//获取option值得方法返回LIST<String>类型
                    data:{'coachId' : coachId},
                    success:function(data){
                        for(var i in data){        //遍历输出LIST添加为option
                            $("#athes").append("<input type='checkbox' name='athleteName' id='checkbox"+data[i].athleteId+"' value='"+data[i].athleteId+"' title='"+data[i].athleteName+"'>" );
                            // $("#athleteName").append("<option value='"+data[i].athleteName+"'>"+data[i].athleteName+"</option>");
                        }
                        if(mothed == 'update'){
                            var schemeId = getQueryString("schemeId");
                            $.ajax({
                                type:"GET",
                                async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                                url:"../../AtsSchemeController/selectAthleteName",//获取option值得方法返回LIST<String>类型
                                data:{'schemeId' : schemeId},
                                success:function(data){
                                    for(var i in data){        //遍历输出LIST添加为option
                                        $("#checkbox"+data[i].athleteId).prop('checked',true);
                                    }
                                }

                            });
                        }



                    }

                });
            }






            /*$.ajax({
                type:"GET",
                async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                url:"../../AtsSchemeController/selectAllCoachs",//获取option值
                success:function(data){
                    for(var i in data){        //遍历输出LIST添加为option
                        $("#coachId").append("<input type='checkbox' name='athleteName' title='"+data[i].athleteName+"' id='"+data[i].athleteId+"'>");
                        // $("#coachName").append("<option value='"+data[i].coachName+"'>"+data[i].coachName+"</option>");

                    }
                }

            });*/

        });

        /*function ath(value) {
            var selectedOption=value.options[value.selectedIndex];
            alert(selectedOption.value);
        }*/

    </script>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <!--<legend>新增方案</legend>-->
</fieldset>

<div><form class="layui-form" action="" id="inputForm" >

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="schemeName" id ="schemeName" lay-verify="required" placeholder="请输入方案名称" autocomplete="off" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">年度</label>
        <div class="layui-input-block">
            <input type="text" name="year" readonly="readonly" lay-verify="required" class="layui-input" id="test2" placeholder="请选择年度">
            <input type="text" name="mothed" id="mothed" hidden>
            <input type="text" name="schemeId" id="schemeId" hidden>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">月份</label>
        <div class="layui-input-block">
            <select name="month" id="month" readonly="readonly" lay-verify="required" lay-filter="month">
                <option value="">--请选择月份--</option>
                <option value="1">1月</option>
                <option value="2">2月</option>
                <option value="3">3月</option>
                <option value="4">4月</option>
                <option value="5">5月</option>
                <option value="6">6月</option>
                <option value="7">7月</option>
                <option value="8">8月</option>
                <option value="9">9月</option>
                <option value="10">10月</option>
                <option value="11">11月</option>
                <option value="12">12月</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="text" name="schemeType" readonly="readonly" id ="schemeType" lay-verify="required" value="运动康复方案" autocomplete="off" class="layui-input">
            <!--<select name="schemeType" lay-verify="required" disabled>
                <option value="运动康复方案">运动康复方案</option>
            </select>-->
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">附件1</label>
        <div class="form-group">
            <div class="col-sm-6">
                <div class="input-group">
                    <input id='location' name="location" lay-verify="files" class="form-control" readonly="readonly"  placeholder="请选择附件" onclick="$('#i-file').click();">
                    <label class="input-group-btn">
                        <input type="button" id="i-check" value="浏览文件" class="btn btn-primary" onclick="$('#i-file').click();">
                    </label>
                </div>
            </div>
            <input type="file" name="f1" id='i-file' accept="*" onchange="$('#location').val($('#i-file').val());" style="display: none">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">附件2</label>
        <div class="form-group">
            <div class="col-sm-6">
                <div class="input-group">
                    <input id='location2' name="location2" placeholder="请选择附件" readonly="readonly" class="form-control" onclick="$('#i-file2').click();">
                    <label class="input-group-btn">
                        <input type="button" id="i-check2" value="浏览文件" class="btn btn-primary" onclick="$('#i-file2').click();">
                    </label>
                </div>
            </div>
            <input type="file" name="f2" id='i-file2' accept="*" onchange="$('#location2').val($('#i-file2').val());" style="display: none">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">附件3</label>
        <div class="form-group">
            <div class="col-sm-6">
                <div class="input-group">
                    <input id='location3' name="location3" class="form-control" readonly="readonly" placeholder="请选择附件" onclick="$('#i-file3').click();">
                    <label class="input-group-btn">
                        <input type="button" id="i-check3" value="浏览文件" class="btn btn-primary" onclick="$('#i-file3').click();">
                    </label>
                </div>
            </div>
            <input type="file" name="f3" id='i-file3'  accept="*" onchange="$('#location3').val($('#i-file3').val());" style="display: none">
        </div>
    </div>

    <!--<div class="layui-form-item">
        <label class="layui-form-label" >运动员ID</label>
        <div class="layui-input-block">
            <select name="athleteId" id="athleteId" lay-verify="required" lay-filter="athletes">
                <option value="">&#45;&#45;请选择对应的运动员ID&#45;&#45;</option>
            </select>
        </div>
    </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label" >运动员姓名</label>
        <div class="layui-input-block" id="athes">
            <!--<input type="checkbox" name="athleteName" lay-verify="required" title="张三" autocomplete="off" class="layui-input">-->
            <!--<input type="checkbox" name="" title="发呆">-->
            <!--<select name="athleteName" id="athleteName" lay-verify="required" disabled>
                <option value="">&#45;&#45;请选择运动员ID-</option>
            </select>-->
        </div>
    </div>

    <div class="layui-form-item" hidden>
        <label class="layui-form-label" >教练员ID</label>
        <div class="layui-input-block">
            <!--<select name="coachId" id="coachId" lay-verify="required" lay-filter="coachs">
                <option value="">&#45;&#45;请选择教练员ID&#45;&#45;</option>
            </select>-->
            <input type="text" name="coachId" id ="coachId" readonly="readonly" placeholder="请输入教练员ID" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" hidden>
        <label class="layui-form-label" >教练员姓名</label>
        <div class="layui-input-block">
            <input type="text" name="coachName" readonly="readonly" id ="coachName" lay-verify="required" placeholder="请输入教练员ID" autocomplete="off" class="layui-input">
            <!--<select name="coachName" id="coachName" lay-verify="required" disabled>
                <option value="">&#45;&#45;请选择教练员ID-</option>
            </select>-->
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" id="testListAction" lay-filter="demo1">立即提交</button>
            <!--<button type="close" class="layui-btn layui-btn-primary" onclick="closeWindow()">关闭</button>-->
        </div>
    </div>
</form></div>



<script type="text/javascript">
    /**
     * 关闭当前弹出层
     */
    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        parent.layui.table.reload('schemeId');
    }

</script>
<script>
    layui.use(['form', 'layedit', 'layer', 'laydate','tree','util','upload'], function(){
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , tree = layui.tree
            ,util = layui.util
            ,upload = layui.upload;

        var months = getQueryString("id");
        $("#month").val(months);
        form.render();

        //自定义验证规则
        form.verify({
            files: function(value){
                if(value.length == 0){
                    return '必须上传附件1';
                }
            }

            ,content: function(value){
                layedit.sync(editIndex);
            }
        });


        //年选择器
        laydate.render({
            elem: '#test2'
            ,type: 'year'
        });

        laydate.render({
            elem:'#creatTime'
            ,value:new Date()
        });

        var i = 0;
        //监听提交
        form.on('submit(demo1)', function(data){

            var kool="";
            $("input[name='athleteName']:checked").each(function(indexs,items){
                kool+=$(this).val();
            });
            if(kool==""){
                layer.msg("请至少选择一名运动员");
                return false;
            }

            var url = "../../AtsSchemeController/add?isva=1";
            var formData = new FormData(document.getElementById("inputForm"));
            //传输路径
            $.ajax({
                url:url,
                type:"post", // 传输类型
                data:formData, // 数据
                async:false, // 全局同步
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    // alert("操作成功");
                    //     layer.alert("操作成功");
                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000,
                        },function(){
                            /*var indexs = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(indexs);*/
                            closeWindow();
                        });
                        return false ;


                },
                error:function(e){
                    alert("操作失败");
                    return false ;
                }
            });

            return false ;
            // closeWindow();//关闭窗口

        });

        // form.on('select(month)',function () {

            /*var athleteId = data.value;
            //var data = {athleteId : athleteId};
            //var url = ;
            $.ajax({
                url:"../../AtsSchemeController/selectAthlete",
                type:"post", // 传输类型
                data:{'athleteId' : athleteId}, // 数据
                //async:false, // 全局同步
                //processData:false,
                //contentType:false,
                dataType:"json",
                success:function(data){
                    var values = data.athleteName;
                    $("#athleteName").val(values);
                    // form.render('select');
                },
                error:function(e){
                    alert('操作失败');

                }
            });*/
           /* $.post(url,data,function (obj) {
                alert(obj.athleteName);
            })*/
        // });

        /*form.on('select(coachs)',function (data) {
            var coachId = data.value;
            //var data = {athleteId : athleteId};
            //var url = ;
            $.ajax({
                url:"../../AtsSchemeController/selectCoach",
                type:"post", // 传输类型
                data:{'coachId' : coachId}, // 数据
                //async:false, // 全局同步
                //processData:false,
                //contentType:false,
                dataType:"json",
                success:function(data){
                    var values = data.coachName;
                    $("#coachName").val(values);
                    // form.render('select');
                },
                error:function(e){
                    alert('操作失败');

                }
            });
            /!* $.post(url,data,function (obj) {
                 alert(obj.athleteName);
             })*!/
        });*/

    });

</script>

</body>
</html>